package com.cuit.jifver.weibo.utils;



import com.cuit.jifver.weibo.R;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

public class ShowDialog 
{
	private  static AlertDialog alertDialog;
	private static Context context;
	private static ShowDialog showDialog = new ShowDialog();
	private boolean isShow;
	
	private ShowDialog()
	{
		
	}
	
	public static ShowDialog getInstance(Context context)
	{
		ShowDialog.context = context;
		if (showDialog == null)
		{
			showDialog = new ShowDialog();
		}
		
		if (alertDialog == null)
		{
			alertDialog = new AlertDialog.Builder(context).create();
		}
		
		return showDialog;
	}
	
	/**
	 * 应用程序退出提示
	 * @param activity
	 */
	public static void quit(final Activity activity) 
	{
		AlertDialog.Builder builder = new Builder(activity);
		builder.setMessage("确认退出吗？");
		builder.setTitle("提示");
		builder.setPositiveButton("确认", new OnClickListener()
		{
			@Override
			public void onClick(DialogInterface dialog, int which)
			{
				dialog.dismiss();
				// Main.this.finish();
				 activity.finish();
			}
		});
		builder.setNegativeButton("取消", new OnClickListener()
		{
			@Override
			public void onClick(DialogInterface dialog, int which)
			{
				dialog.dismiss();
			}
		});
		builder.create().show();
	}
	
	
	public static void warn(Context con, String message)
	{
		AlertDialog.Builder builder = new Builder(con);
		builder.setTitle("提示");
		builder.setMessage(message);
		builder.setPositiveButton("确认", new OnClickListener()
		{
			
			@Override
			public void onClick(DialogInterface dialog, int which)
			{
				dialog.dismiss();
			}
		});
	}
	
	
	
	
	public static void radioDilog(Context context, String title, int icon)
	{
		if (context == null)
		{
			return;
		}
		Builder builder = new AlertDialog.Builder(context);
		if (title != null)
		{
			builder.setTitle(title);
		}
		if (icon != 0)
		{
			builder.setIcon(icon);
		}
	//	builder.setSingleChoiceItems(arg0, arg1, arg2)
		
	}
	
	
	public void showWritingDialog(String text)
	{
		LayoutInflater inflater = LayoutInflater.from(context);
		View view = inflater.inflate(R.layout.writingdialog,null);
		TextView tView = (TextView) view.findViewById(R.id.writingdialog_tv);
		tView.setText(text);
		alertDialog.show();
		alertDialog.getWindow().setContentView(view);
		isShow = true;
	}
	
	
	  public void dimissWritingDialog() {
		  
		  if (alertDialog != null && isShow)
		{
			  alertDialog.dismiss();
		}
			
			isShow = false;
		}

}
